﻿CREATE PROCEDURE [dbo].[Purchase_CreateItem]
	@userId UNIQUEIDENTIFIER,
	@bookId UNIQUEIDENTIFIER,
	@value NVARCHAR(16)
AS
BEGIN
/*	SELECT @value = [TotalCost]
	FROM [dbo].[ebook_Item]
	WHERE [BookId] = @bookId*/


	--DECLARE @chapterId UNIQUEIDENTIFIER
	--DECLARE @price NVARCHAR(128)
	--DECLARE @isPublishedChapter BIT

	--SELECT @price = [Cost], @chapterId = [ChapterId], @isPublishedChapter = [IsPublished]
	--FROM [dbo].[text_Chapter]
	--WHERE [HashTag] = @chapterHashTag

	--IF @price IS NULL
	--	RAISERROR ('UnknownPurchase', 16, 1)

	DECLARE @purchaseId BIGINT
	INSERT INTO [dbo].[purchase_Item]
							([UserId]
							,[Value]
							,[BookId])
	VALUES
							(@userId
							,@value
							,@bookId)

	SET @purchaseId = SCOPE_IDENTITY()


	SELECT [PurchaseId]
				,[PurchaseHashCode]
				,[Value]
  FROM [dbo].[purchase_Item]
	WHERE [PurchaseId] = @purchaseId

END